import CryptoJS from 'crypto-js'

export default {
    // 随机生成指定数量的16进制key

    // 加密
    encrypt (word, keyStr) {
        var key = CryptoJS.enc.Utf8.parse(keyStr)
        var encryptedData = CryptoJS.AES.encrypt(word, key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        })
        return CryptoJS.enc.Base64.stringify(encryptedData.ciphertext)
    },
    // 解密
    decrypt (word, keyStr) {
        keyStr = keyStr || null
        var key = CryptoJS.enc.Utf8.parse(keyStr)
        var decrypt = CryptoJS.AES.decrypt(word, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
        return CryptoJS.enc.Utf8.stringify(decrypt).toString()
    }
}
